#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
 
int main()
{
   int fbfd=0;//framebuffer 文件句柄
   struct fb_var_screeninfo vinfo;
   unsigned long screen_size=0;
   char *fbp=0;//framebuffer 在用户空间映射的虚拟地址指针
   int x=0,y=0,i=0;
 
   fbfd=open("/dev/fb0",O_RDWR);  //打开framebuffer 文件节点
   if(!fbfd){
		  printf("error\n");
		  exit(1);
   }
 
   if(ioctl(fbfd,FBIOGET_VSCREENINFO,&vinfo)){  //获取屏幕可变参数
		  printf("error\n");
		  exit(1);
   }
 
   //打印屏幕可变参数：x轴像素个数，y轴像素个数，每个像素点数
   printf("%dx%d,%dbpp\n",vinfo.xres,vinfo.yres,vinfo.bits_per_pixel);
   screen_size=vinfo.xres*vinfo.yres*12;  //framebuffer大小
   fbp=(char *)mmap(0,screen_size,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0);//映射
   if((int)fbp==-1){
		  printf("error\n");
		  exit(4);
   }
 
   for(i = 0; i < screen_size/2; i++)
   {
	   unsigned short rgb;
	   rgb=(31<<11)|(0<<5)|0;
	   *((unsigned short *)(fbp+i*2))=rgb;
   }
 
   munmap(fbp,screen_size);
   close(fbfd);
   return 0;
}